﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using QUANLIBANHANG.ENTITY;
namespace QUANLIBANHANG.DAL
{
    public class HoadonDAL
    {
        // Insert hóa đơn DAL
        public static void insertHD(HoadonEntity hd)
        {
            try
            {
                ConnectionSQL.commandSQL("INSERT INTO HOADON (NGAYHD, MAKH, MANV, TRIGIA) VALUES ('" + hd.Ngayhd + "','" + hd.Makh + "','" + hd.Manv + "','" + hd.Trigia + "')");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //Update hóa đơn DAL
        public static void updateHD(HoadonEntity hd)
        {
            try
            {
                ConnectionSQL.commandSQL("UPDATE HOADON SET NGAYHD ='" + hd.Ngayhd + "', MAKH ='" + hd.Makh + "', MANV ='" + hd.Manv + "', TRIGIA =" + hd.Trigia);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void deleteHD(HoadonEntity hd)
        {
            try
            {
                ConnectionSQL.commandSQL("DELETE FROM HOADON WHERE SOHD=" + hd.Sohd);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable getTableHD(string dk)
        {
            try
            {
                return ConnectionSQL.getTable("SELECT * FROM HOADON" + dk);

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static DataTable getTableHDDoanhThu(string start, string end)
        {
            try
            {
                return ConnectionSQL.getTable(String.Format("SELECT * FROM HOADON WHERE  NGAYHD BETWEEN  '{0}' AND '{1}'", start, end));

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
       
    }
}
